package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class DelOperation implements IOperation{

    public void work(BookList bookList){
        System.out.println("删除图书");
        System.out.println("请输入你要删除的图书");
        String name = scanner.nextLine();
        int size = bookList.getUseSize();
        for (int i = 0; i < size; i++) {
            Book book = bookList.getPos(i);
            if(name.equals(book.getName()) == true){
                int j = i;
                for (; j < size - 1; j++) {
                    bookList.setPos(j,bookList.getPos(j+1));
                }
                bookList.setPos(j,null);
                bookList.setUseSize(size-1);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("没有你要删除的图书");
    }
}
